import { ref } from "vue";
import type { Ref } from "vue";
// 状态和数据之间的解耦合
export interface Count {
  count: Ref<number>;
  add: () => void;
  reduce: () => void;
}

const useCount = (initialValue: number = 0, step: number = 1): Count => {
  const count = ref(initialValue);

  const add = () => {
    count.value += step;
  };
  const reduce = () => {
    count.value -= step;
  };

  return {
    count,
    add,
    reduce,
  };
};

export default useCount;
